package SIC.Controleur.XMLAdapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class HashMapAdapter extends XmlAdapter<MyHashMapContent<String , List<String>>, HashMap<String, List<String>>> {
	
	@Override
	public MyHashMapContent<String,List<String>> marshal(HashMap<String, List<String>> arg0) throws Exception {
		
		MyHashMapContent<String,List<String>> ret = new MyHashMapContent<String,List<String>>();
		
		for (Entry<String,List<String>> entry : arg0.entrySet())
		{
			HashMapEntry myHashEntryType = new HashMapEntry(entry.getKey(),entry.getValue());	
			ret.entries.add(myHashEntryType);
		}
		return ret;
	}
	
	@Override
	public HashMap<String, List<String>> unmarshal(MyHashMapContent<String,List<String>> arg0) throws Exception {
		
		HashMap<String, List<String>> hashMap = new HashMap<String, List<String>>();
		
		for (HashMapEntry myHashEntryType : arg0.entries)
			hashMap.put(myHashEntryType.key, myHashEntryType.value);
		
		return hashMap;
	}

}




